package com.jinxiangyang.utils;


import com.jinxiangyang.domain.Git;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * git
 */
public class GitUtils {
        public static List<Git> getGitInformation() {
            String cmd = "git log --date=iso --pretty=format:%h,%an,%ad,%s";
            ArrayList<Git> gits = new ArrayList<>();
            try {
                Process process = Runtime.getRuntime().exec(cmd);
                InputStream is = process.getInputStream();
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String content = br.readLine();
                while (content != null) {
                    String[] split = content.split(",");
                    Git git = new Git(split[0], split[3], split[2], split[1]);
                    gits.add(git);
                    content = br.readLine();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return  gits;
        }
}

